<template>
  <div v-show="settingFontPopup" class="book-popop-list">
    <div class="book-popup-title">
      <div class="book-popup-title-iocn" @click="hidPopup">
        <span class="icon-down2" />
      </div>
      <span class="book-popup-title-text">{{ $t('book.selectFont') }}</span>
    </div>
    <div class="book-popup-menu">
      <div v-for="(item, index) in fontList" :key="index" class="book-popup-item" @click="setFontFamily(item)">
        <div class="book-popup-item-title" :class="{'selected': isSelected(item)}">{{ item.font }}</div>
        <div v-if="isSelected(item)" class="ebook-popup-item-check">
          <span class="icon-check" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ebookMixin } from '../../mixin/mixin'
import { FONT_FAMILY } from '../../mixin/book'
import { saveFontFamily } from '../../utils/localStorage'
export default {
  mixins: [ebookMixin],
  data() {
    return {
      fontList: FONT_FAMILY
    }
  },
  methods: {
    hidPopup() {
      this.$store.dispatch('book/setSettingFontPopup', false)
    },
    isSelected(item) {
      return this.defaultFontFamily === item.font
    },
    setFontFamily(item) {
      this.$store.dispatch('book/setDefaultFontFamily', item.font)
      saveFontFamily(this.fileName, item.font)
      if (item.font === 'Default') {
        this.currentBook.rendition.themes.font('Times New Roman')
      } else {
        this.currentBook.rendition.themes.font(item.font)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../../style/index';
.book-popop-list {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 300;
    background: white;
    width: 100%;
    box-shadow: 0 px2rem(-4) px2rem(6) rgba(0, 0, 0 ,.1);
    .book-popup-title {
        position: relative;
        padding: px2rem(20);
        box-shadow: border-box;
        border-bottom: px2rem(1) solid #b8b9bb;
        text-align: center;
        @include center;
        .book-popup-title-iocn {
            position: absolute;
            left: px2rem(15);
            top: 0;
            height: 100%;
            font-size: px2rem(16);
            font-weight: bold;
            @include center;
        }
        .book-popup-title-text {
            font-size: px2rem(16);
        }
    }
    .book-popup-menu {
      .book-popup-item {
        display: flex;
        padding: px2rem(15);
        .book-popup-item-title {
          flex: 1;
          text-align: left;
          font-size: px2rem(14);
          &.selected {
            color: #346cd9;
            font-weight: bold;
          }
        }
        .ebook-popup-item-check {
          flex: 1;
          text-align: right;
          font-size: px2rem(14);
          font-weight: bold;
          color: #346cd9;
        }
      }
    }
}
</style>
